$(function(){
	var $mrAdd = $('.mr-add');
	var $addOnly = $('.mr-add-only');
	var $hoverImg = $('.resume-hover-img');
	var $mrOptions = $('.mr-options');
	var $mrOptionsLi = $('.mr-options ul li');
	var $window = $(window);
	var $moduleEdit = $('.module-edit');
	var $choose = $('.choose');
	/*var $show = $('.show');
	var $mrAdd = $('.mr-add');
	var $downLoad = $('.down-load');*/
	
	// 鼠标经过头像框，显示照相机
	$('#input-file').hover(function(){
		$('.resume-hover-img').css('display','block');
	},function(){
		$('.resume-hover-img').css('display','none');
	})
	
	// 点击修改出现输入框
	$mrAdd.click(function(){
		$(this).children('span').toggle();
		$(this).parent().next().css('display','none');
		$(this).parents('section').next().css('display','block');
	});
	
	//点击只添加
	$addOnly.click(function(){
		$(this).parent().siblings('.user-message').before($(this).parent().next().html());
		$(this).parent().siblings('.mr-form').css('display','block');
	})
	
	// 点击编辑
	$moduleEdit.click(function(){
		$(this).parents('.items').next().css('display','block');
	})
	
	// 侧边栏点击变色
	$mrOptionsLi.click(function(){
		$mrOptionsLi.removeClass('active');
		$(this).addClass('active');
		$mrOptionsLi.children('i').removeClass('active');
		$(this).children('i').addClass('active');
	})
	
	
	// 侧边栏滑动到相应位置变色
	$window.scroll(function(){
		// 侧边栏滑动一定距离，位置固定
		var $scrollTop = $(window).scrollTop();
		if($scrollTop >= 129){
			$mrOptions.css({'position':'fixed','top':'0'});
		}else{
			$mrOptions.css('position','static');
		}
		/*var $position = $(document).scrollTop();
		var $position1 = $('#wishJob').offset().top;
		console.info($position1 - $position);*/
		var $baseInfo = $('#baseInfo').offset().top;
		var $wishJob = $('#wishJob').offset().top;
		var $workExperience = $('#workExperience').offset().top;
		var $itemExperience = $('#itemExperience').offset().top;
		var $educationExperience = $('#educationExperience').offset().top;
		var $selfAssessment = $('#selfAssessment').offset().top;
		// 点击滑动到指定位置
		$('.to-base').click(function(){
			$('body:not(:animated)').animate({scrollTop: $baseInfo},300);
//			$('body:not(:animated)').animate({scrollTop: $('#baseInfo').offset().top},300);
		});
		$('.to-wish').click(function(){
//			$('body:not(:animated)').animate({scrollTop: $wishJob},300);
			$('body:not(:animated)').animate({scrollTop: $('#wishJob').offset().top},300);
		});
		$('.to-work').click(function(){
			$('body:not(:animated)').animate({scrollTop: $('#workExperience').offset().top},300);
		});
		$('.to-item').click(function(){
			$('body:not(:animated)').animate({scrollTop: $('#itemExperience').offset().top},300);
//			$('body:not(:animated)').animate({scrollTop: $itemExperience},300);
		});
		$('.to-education').click(function(){
			$('body:not(:animated)').animate({scrollTop: $('#educationExperience').offset().top},300);
//			$('body:not(:animated)').animate({scrollTop: $educationExperience},300);
		});
		$('.to-self').click(function(){
			$('body:not(:animated)').animate({scrollTop: $('#selfAssessment').offset().top},300);
//			$('body:not(:animated)').animate({scrollTop: $selfAssessment},300);
		});
		// 滚动到指定位置变亮
		$('.mr-options ul li').removeClass('active');
		if($scrollTop <= $wishJob){
			$('.to-base').addClass('active');
		}
		if($scrollTop > $wishJob && $scrollTop <= $workExperience){
			$('.to-wish').addClass('active');
		}
		if($scrollTop > $workExperience && $scrollTop <= $itemExperience){
			$('.to-work').addClass('active');
		}
		if($scrollTop > $itemExperience && $scrollTop <= $educationExperience){
			$('.to-item').addClass('active');
		}
		if($scrollTop > $educationExperience && $scrollTop <= $selfAssessment){
			$('.to-education').addClass('active');
		}
		if($scrollTop > $selfAssessment){
			$('.to-self').addClass('active');
		}
	});
	
	/*//点击出现下滑列表
	
	// 点击下滑社交选项框
	$show.click(function(){
		$('.show-kinds:not(:animated)').slideToggle();
	});
	
	// 点击出现添加选项,同时文字变成取消
	$mrAdd.click(function(){
		$(this).children('span').toggle();
		$(this).parent().next().toggle();
	});
	
	// 点击编辑对经历进行编辑
	$moduleEdit.click(function(){
		$(this).parents('.mr-content').css('display','none');
		$(this).parents('.mr-content').next().css('display','block');
	});
	
	// 侧边栏点击字体颜色改变
	
	//点击选择下载类型
	$downLoad.click(function(){
		$('.file-type').toggle();
	})*/
	
	// 点击添加到choose,同时收上去
	var $detailItemUl = $('.detail-item ul');
	var $detailItemLi = $('.detail-item ul li');
	var $detailItemChoose = $('.detail-item .choose');
	//点击li，收上去
	$detailItemLi.click(function(){
		event.stopPropagation();
		$(this).parent().prev().children('span').html($(this).html());
		$(this).parent().slideUp();
		$(this).addClass('li-active');
	})
	// 点击收上去、滑下来
	$detailItemChoose.click(function(){
		event.stopPropagation();
		$(this).next().slideToggle();
	})
	// 点击任意一处，ul收上去
	$('html,body').click(function(){
		$detailItemUl.slideUp();
	})
	
	// 性别选择
	var $mrSexChoose = $('.mr-sex');
	$mrSexChoose.click(function(){
		$mrSexChoose.removeClass('active');
		$(this).addClass('active');
	})
	
	/**
	 * 基本信息
	 */
	var $mrName = $('#mrName');
	var $mrNameInput = $('#mrNameInput');
	var $mrIntrduce = $('#mrIntrduce');
	var $mrIntrduceInput = $('#mrIntrduceInput');
	var $mrSex = $('#mrSex');
	var $mrSexInput = $('.sex .active');
	var $mrBirthday = $('#mrBirthday');
	var $mrBirthdayInput = $('#mrBirthdayInput');
	var $mrEducation = $('#mrEducation');
	var $mrEducationInput = $('#mrEducationInput');
	var $mrWorkExperience = $('#mrWorkExperience');
	var $mrWorkExperienceInput = $('#mrWorkExperienceInput');
	var $mrCity = $('#mrCity');
	var $mrCityInput = $('#mrCityInput');
	var $mrPhone = $('#mrPhone');
	var $mrPhoneInput = $('#mrPhoneInput');
	var $mrEmail = $('#mrEmail');
	var $mrEmailInput = $('#mrEmailInput');
	var $baseInfoSave = $('#baseInfoSave');
	var $baseInfoCancel = $('#baseInfoCancel');
	var $baseForm = $('#baseForm');
	var $baseInfoArticle = $('#baseInfoArticle');
	$baseInfoSave.click(function(){
		$mrName.html($mrNameInput.val());
		$mrIntrduce.html($mrIntrduceInput.val());
		$mrSex.html($mrSexInput.html());
		$mrBirthday.html($mrBirthdayInput.html());
		$mrEducation.html($mrEducationInput.html());
		$mrWorkExperience.html($mrWorkExperienceInput.html());
		$mrCity.html($mrCityInput.html());
		$mrPhone.html($mrPhoneInput.val());
		$mrEmail.html($mrEmailInput.val());
		$baseForm.hide();
		$baseInfoArticle.show();
	})
	$baseInfoCancel.click(function(){
		$baseInfoArticle.show();
		$baseForm.hide();
	})
	
	
	/**
	 * 期望工作
	 */
	var $wishWorkAdd = $('#wishWorkAdd');
	var $wishWorkEdit = $('#wishWorkEdit');
	var $wishWorkForm = $('#wishWorkForm');
	var $wishWorkSave = $('#wishWorkSave');
	var $wishWorkCancel = $('#wishWorkCancel');
	var $wishWork = $('#wishWork');
	var $wishWorkInput = $('#wishWorkInput');
	$wishWorkAdd.click(function() {
		$wishWorkForm.show();
	});
	$wishWorkEdit.click(function() {
		$wishWorkForm.show();
		$wishWork.hide();
		$wishWorkInput.val($wishWork.html());
	});
	$wishWorkSave.click(function() {
		var wishWorkInputVal = $.trim($wishWorkInput.val());
		if (wishWorkInputVal != '') {
			$wishWork.html(wishWorkInputVal);
			$wishWork.show();
			$wishWorkForm.hide();
			$wishWorkAdd.hide();
			$wishWorkEdit.show();
		} else {
			alert('输入的期望职位不能为空！');
		}
	});
	$wishWorkCancel.click(function() {
		$wishWorkForm.hide();
		$wishWorkInput.val('');
		$wishWork.show();
	});
	
})
